﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Linq.Expressions;
using System.Reflection;

namespace spktNhom4DoAnCuoiKy
{
    public static class MyMethod
    {
        public static string GetNewCode<T>(this IQueryable<T> collection ,string columnName,string prefix)
        {
           
            Type type = typeof(T);
            if (collection.Count()==0) return (prefix + String.Format("{0:d4}",1));
            int max = collection.Select(x => int.Parse(type.GetProperty(columnName).GetValue(x, null).ToString().Substring(prefix.Length))).ToList().Max();


              return (prefix + String.Format("{0:d4}",max+1));
            
           


        }
    }
}